<?php
/**
 * 会员自助广告位管理 - 织梦技术研究中心！
 *
 * @version        $Id: mad_list.php 14:31:15 2013年10月10日 土匪 $
 * @package        DedeCMS menber ad
 * @copyright      Copyright (c) 2013, Dedejs.com
 * @link           http://bbs.dedejs.com
 */
require_once(dirname(__FILE__)."/config.php");
CheckPurview('mad_list');
require_once(DEDEINC.'/datalistcp.class.php');
setcookie("ENV_GOBACK_URL",$dedeNowurl,time()+3600,"/");
$db->SetQuery("SELECT aid,name FROM #@__memad_type");
$db->Execute();
$options = '';
while($rs = $db->GetArray())
{
$options .= "<option value='".$rs['aid']."'>".$rs['name']."</option>\r\n";
}
/*
function look();
*/
if($action=='look')
{
	$row = $db->GetOne("Select c.cid,c.mcid,m.* FROM #@__memad c left join #@__member m on c.mcid=m.mid where cid='$cid'");
	AjaxHead();
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="28" width="90">购买者信息</td>
<td colspan="2"></td><td width="20" align="right" valign="top"><a href="javascript:CloseEditCatalog()"><img src="images/close.gif" width="12" height="12" border="0" /></a></td>
</tr>
<tr>
<td width="150" height="28">注册ID：</td>
<td width="240"><?php echo $row['mid']; ?></td>
</tr>
<tr>
<td width="150" height="28">昵称or公司名称：</td>
<td width="240"><?php echo $row['uname']; ?></td>
</tr>
<tr>
<td width="90" height="28">现有积分：</td>
<td width="40"><?php echo $row['scores']; ?></td>
</tr>
<tr>
<td width="70" height="28">现有金币：</td>
<td width="40"><?php echo $row['money']; ?></td>
</tr>
<tr>
<td width="90" height="28">会员类型：</td>
<td width="120"><?php echo $row['mtype']; ?>会员</td>
</tr>
<tr>
<td width="90" height="28">注册时间：</td>
<td width="120"><?php echo GetDateMk($row['jointime'])?></td>
</tr>
<tr>
<td width="90" height="28">邮箱：</td>
<td width="120"><?php echo $row['email']; ?></td>
</tr>
</table>
<?php
exit();
}
if($action=="add")
{
	$tid = ereg_replace("[^0-9]","",$tid);
	$lists = ereg_replace("[^0-9]","",$lists);
	$price = ereg_replace("[^0-9]","",$price);
	$slaes = ereg_replace("[^0-9]","",$slaes);
	$tagname = trim($tagname);
	if(empty($adname))
	{
		ShowMsg('广告名称不能为空','mad_list.php');
			exit();
	}
	else if(empty($tid))
	{
		ShowMsg('所属分类不能为空','mad_list.php');
			exit();
	}
	else if(empty($price))
	{
		ShowMsg('广告价格不能为空','mad_list.php');
			exit();
	}
	else
	{
		$sql = "insert into `#@__memad`(tid,adname,price,lists,adtype,sales,expbody,litpic)  values('$tid','$adname','$price','$lists','$adtype','$sales','$expbody','$litpic'); ";
		if($dsql->ExecuteNoneQuery($sql))
			{
		ShowMsg('成功增加一个广告位，请获取代码后粘贴到相应位置！','mad_list.php');
			exit();
			}
		else{ShowMsg('添加失败，请将该错误提交到织梦技术研究中心！','mad_list.php');
			exit();}
    }
}
else if($action=="del"&&isset($cid))
{
	$db->ExecuteNoneQuery("DELETE FROM #@__memad WHERE cid='$cid'");
	ShowMsg('删除成功！现在将返回管理页面','mad_list.php');
			exit();
}
elseif($action == 'edit')
{
if(empty($step))
	{
		$sql = "Select c.*,m.name FROM #@__memad c left join #@__memad_type m on c.tid=m.aid where cid='$cid'  ";
		$sector = $dsql->GetOne($sql);

     if($sector['adtype']=='1'){
	$nbody = "<tr><td width=150 height=20 align=right bgcolor=#FFFFFF>文字内容：</td><td height=20 bgcolor=#FFFFFF><input name=normbody type=text size=50 value={$sector['normbody']} ></td></tr><tr><td width=150 height=20 align=right bgcolor=#FFFFFF>文字链接：</td><td height=20 bgcolor=#FFFFFF><input name=normurl type=text size=50 value={$sector['normurl']} ></td></tr>";
	$ebody = "<tr><td width=150 height=20 align=right bgcolor=#FFFFFF>文字内容：</td><td height=20 bgcolor=#FFFFFF><input name=expbody type=text size=50 value={$sector['expbody']} ></td></tr><tr><td width=150 height=20 align=right bgcolor=#FFFFFF>文字链接：</td><td height=20 bgcolor=#FFFFFF><input name=expurl type=text size=50 value={$sector['expurl']} ></td></tr>";
	}
    elseif($sector['adtype']=='2'){
    $nbody = "<tr><td width=150 height=20 align=right bgcolor=#FFFFFF>图片地址：</td><td height=20 bgcolor=#FFFFFF><input name=normbody type=text size=50 value={$sector['normbody']} ></td></tr><tr><td width=150 height=20 align=right bgcolor=#FFFFFF>图片链接：</td><td height=20 bgcolor=#FFFFFF><input name=normurl type=text size=50 value={$sector['normurl']} ></td></tr>";
    $ebody = "<tr><td width=150 height=20 align=right bgcolor=#FFFFFF>图片地址：</td><td height=20 bgcolor=#FFFFFF><input name=expbody type=text size=50 value={$sector['expbody']} >  <input type=button name=Submitss value=站内选择 onClick=SelectImage('form2.expbody','');></td></tr><tr><td width=150 height=20 align=right bgcolor=#FFFFFF>图片链接：</td><td height=20 bgcolor=#FFFFFF><input name=expurl type=text size=50 value={$sector['expurl']} ></td></tr>";
     }
     else{
	$nbody = "<tr><td width=150 height=20 align=right bgcolor=#FFFFFF>Flash地址：</td><td height=20 bgcolor=#FFFFFF><input name=normbody type=text size=50 value={$sector['normbody']} > </td></tr>";
	$ebody = "<tr><td width=150 height=20 align=right bgcolor=#FFFFFF>Flash地址：</td><td height=20 bgcolor=#FFFFFF><input name=expbody type=text size=50 value={$sector['expbody']} > <input type=button name=Submitss value=站内选择 onClick=SelectMedia('form2.expbody','');></td></tr>";
    }
    $dsql->SetQuery($sql);
	$dsql->Execute();
	include(DEDEADMIN."/templets/mad_list.htm");
		exit();
	}
	else if($step == 2)
	{
		$sql = "update `#@__memad` set tid='$tid',adname='$adname',price='$price', lists='$lists',adtype='$adtype', sales='$sales', litpic='$litpic', times='$times',normbody='$normbody',normurl='$normurl', expbody='$expbody',expurl='$expurl' where cid='$cid' ";
		if($dsql->ExecuteNoneQuery($sql))
		{
			ShowMsg('修改广告位成功，现在将返回管理页面','mad_list.php');
			exit();
		}
		else
		{
			ShowMsg('修改失败，请将该错误提交到织梦技术研究中心！','mad_list.php');
			exit();
		}
	}
}
else if($action=="getjs")
{
	require_once(DEDEINC.'/oxwindow.class.php');
	$jscode = "<script src='{$cfg_phpurl}/mad_js.php?cid=$cid' language='javascript'></script>";
	$showhtml = "<xmp style='color:#333333;background-color:#ffffff'>\r\n\r\n$jscode\r\n\r\n</xmp>";
	$showhtml .= "预览：<iframe name='testfrm' frameborder='0' src='mad_list.php?cid={$cid}&action=testjs' id='testfrm' width='100%' height='350'></iframe>";
	$wintitle = "会员自助广告管理-获取广告代码";
	$wecome_info = "<a href='mad_list.php'><b>返回管理界面</b></a>::获取广告代码";
	$win = new OxWindow();
	$win->Init();
	$win->AddTitle("以下为选定广告的JS调用代码，请将代码复制后粘贴到模板相应位置：");
	$winform = $win->GetWindow("hand",$showhtml);
	$win->Display();
	exit();
}
else if($action=='testjs')
{
	echo "<script src='{$cfg_phpurl}/mad_js.php?cid=$cid' language='javascript'></script>";
	exit();
}
else if($action=='uprank')
{
	foreach($_POST as $rk=>$rv)
	{
		if(ereg('rank',$rk))
		{
			$cid = str_replace('rank_','',$rk);
			$db->ExecuteNoneQuery("UPDATE #@__memad SET lists='{$rv}' WHERE cid='{$cid}'");
		}
	}
	ShowMsg('更新排序成功，现在将返回广告管理页面','mad_list.php')
		;exit();

}
$wheresql = "WHERE cid>0";
if($tid > 0)
{
	$wheresql .= " AND (tid='".$tid."')";
}

if($sales > 0)
{
	$wheresql .= " AND (sales='".$sales."')";
}
if($type > 0)
{
	$wheresql .= " AND (adtype='".$type."')";
}
if($price1 > 0)
{
	$wheresql .= " AND (price>='".$price1."')";
}
if($price2 > 0)
{
	$wheresql .= " AND (price<='".$price2."')";
}

$sql = "SELECT c.*,m.name,l.userid FROM #@__memad c left join #@__memad_type m on c.tid=m.aid left join #@__member l on c.mcid=l.mid $wheresql order by c.tid,c.lists ";
$dl = new DataListCP();
$dl->pageSize = 10;
$dl->SetParameter("tid",$tid);
$dl->SetParameter("sales",$sales);
$dl->SetParameter("type",$type);
$dl->SetParameter("price1",$price1);
$dl->SetParameter("price2",$price2);
//这两句的顺序不能更换
$dl->SetTemplate(DEDEADMIN."/templets/mad_list.htm");
$dl->SetSource($sql); 
$dl->Display();

?>